import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'homepagehttp.dart';

class Homepage extends StatefulWidget {
  Homepage() {
    print("初始化");
  }

  @override
  _HomepageState createState() => _HomepageState();
}

class _HomepageState extends State<Homepage> {
  int countNmuber = 1;

  @override
  void initState() {
    super.initState();
    Map userInfo = {"name": "yihu", "age": 25};

    print(userInfo);
    //{"name":"yihu","age":25} 把map 转换成json 字符串
    var a = json.encode(userInfo);
    print(a is String);

    String userinfoString = '{ "name":"yihu","age":28}';
    //json字符串转换成map
    print(json.decode(userinfoString));
    print(json.decode(userinfoString) is Map); //true

    HomepageHttp.getdata().then((value) {
      print(value);
    });
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
        child: Wrap(
      spacing: 20.0,
      children: <Widget>[
        Chip(
          label: Text("$countNmuber"),
        ),
        RaisedButton(
          child: Text("点我 提交数据"),
          onPressed: () {
            HomepageHttp.postData({"username": "张三", "age": "15"})
                .then((value) {
              print(value);
            });
          },
        ),
        RaisedButton(
          child: Text("跳转到搜索页面"),
          onPressed: () {
            Navigator.pushNamed(context, '/search');
          },
        ),
        RaisedButton(
          child: Text("跳转到tabbar页面"),
          onPressed: () {
            Navigator.pushNamed(context, '/tabbardemo');
          },
        ),
        RaisedButton(
          child: Text("跳转到TabBarControllerPage页面"),
          onPressed: () {
            Navigator.pushNamed(context, '/tabBarController');
          },
        ),
        RaisedButton(
          child: Text("CustomScrollView"),
          onPressed: () {
            Navigator.pushNamed(context, '/CustomScrollView');
          },
        ),
        RaisedButton(
          child: Text("吸顶tab"),
          onPressed: () {
            Navigator.pushNamed(context, '/TabbarFixd');
          },
        ),
        RaisedButton(
          child: Text("表单"),
          onPressed: () {
            Navigator.pushNamed(context, '/formTest');
          },
        ),
        RaisedButton(
          child: Text("表单控制器"),
          onPressed: () {
            Navigator.pushNamed(context, '/FormTestController');
          },
        ),
        RaisedButton(
          child: Text("官方日期时间"),
          onPressed: () {
            Navigator.pushNamed(context, '/datatime');
          },
        ),
        RaisedButton(
          child: Text("第三方日期时间"),
          onPressed: () {
            Navigator.pushNamed(context, '/datatimeplu');
          },
        ),
        RaisedButton(
          child: Text("请求"),
          onPressed: () {
            Navigator.pushNamed(context, '/httpDemo');
          },
        ),
        RaisedButton(
          child: Text("新闻列表"),
          onPressed: () {
            Navigator.pushNamed(context, '/newlist');
          },
        ),
        RaisedButton(
          child: Text("设备信息"),
          onPressed: () {
            Navigator.pushNamed(context, '/device');
          },
        ),
        RaisedButton(
          child: Text("位置信息"),
          onPressed: () {
            Navigator.pushNamed(context, '/location');
          },
        ),
        RaisedButton(
          child: Text("图片上传"),
          onPressed: () {
            Navigator.pushNamed(context, '/imagepick');
          },
        ),
        RaisedButton(
          child: Text("视频播放"),
          onPressed: () {
            Navigator.pushNamed(context, '/videoplay');
          },
        ),
        RaisedButton(
          child: Text("网络检查"),
          onPressed: () {
            Navigator.pushNamed(context, '/nexwork');
          },
        ),
        RaisedButton(
          child: Text("本地存储"),
          onPressed: () {
            Navigator.pushNamed(context, '/localstorage');
          },
        ),
        RaisedButton(
          child: Text("扫一扫"),
          onPressed: () {
            Navigator.pushNamed(context, '/sacn');
          },
        ),
        RaisedButton(
          child: Text("检查版本升级"),
          onPressed: () {
            Navigator.pushNamed(context, '/version');
          },
        ),
        RaisedButton(
          child: Text("打开浏览器和拨打电话"),
          onPressed: () {
            Navigator.pushNamed(context, '/urllaunch');
          },
        ),
        RaisedButton(
          child: Text("支付宝支付"),
          onPressed: () {
            Navigator.pushNamed(context, '/alipay');
          },
        ),
      ],
    ));
  }
}
